package com.ls.demo.bean;

import com.ls.demo.enums.CommandTypeEnum;
import com.ls.demo.enums.MessageAttrEnum;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

/**
 * @author liShan
 * @date 2019/9/5 9:20
 */
@Getter
@Setter
@ToString
public abstract class BaseCommand implements Serializable {

    /**
     * @see MessageAttrEnum
     */
    private String messageAttr;
    private RoomBoxInfo boxInfo;

    public BaseCommand() {
    }

    public BaseCommand(String messageAttr) {
        this.messageAttr = messageAttr;
    }

    /**
     * 给命令赋值，比如目标和源目标地址，报文属性， 酒店栋数，酒店号
     * @param command 命令对象
     */
    public void assCommand(Command command){
        command.setTarAddrHigh(Integer.toHexString(this.boxInfo.getLayerNum()));
        command.setTarAddrLow(Integer.toHexString(this.boxInfo.getRoomNum()));
        command.setSrcAddrHigh(CommandTypeEnum.DOWNLOAD.getPcHigh());
        command.setSrcAddrHigh(CommandTypeEnum.DOWNLOAD.getPcLow());
        command.setMessageAttr(this.messageAttr);
        command.setBuildingNum(Integer.toHexString(this.boxInfo.getBuildingNum()));
        command.setHotelNumHigh(Integer.toHexString(this.boxInfo.getHotelHigh()));
        command.setHotelNumLow(Integer.toHexString(this.boxInfo.getHotelLow()));
    }

}
